package controllers

import (
	"github.com/astaxie/beego"
	"helloCms/models"
	"github.com/astaxie/beego/orm"
)

type LoginController struct {
	beego.Controller
}

func (c *LoginController)Index()  {
	c.TplName="Login/Index.html"
}

func (c *LoginController)UserLogin()  {
	userInfo:=models.Userinfo{
		UserName:c.GetString("LoginCode"),
		UserPwd:c.GetString("LoginPwd"),
	}
	o:=orm.NewOrm()
	err:=o.Read(&userInfo,"UserName","UserPwd")
	if err!=nil{
		//beego.Info(err)
		c.Data["json"]=map[string]interface{}{"flag":"no"}
	}else {
		c.SetSession("userId",userInfo.Id)
		c.SetSession("userName",userInfo.UserName)
		c.Data["json"]=map[string]interface{}{"flag":"ok"}
	}
	c.ServeJSON()
}